<template>
  <view class="webview-page">
    <web-view :src="url" class="webview-content" @message="onMessage" @error="onError"></web-view>
  </view>
</template>

<script>
export default {
  name: 'WebView',
  data() {
    return {
      url: '',
      title: ''
    }
  },
  onLoad(options) {
    console.log('WebView页面参数:', options);
    this.url = decodeURIComponent(options.url || '');
    this.title = decodeURIComponent(options.title || '文件预览');
    
    // 设置导航栏标题
    uni.setNavigationBarTitle({
      title: this.title
    });
    
    console.log('WebView URL:', this.url);
  },
  methods: {
    onMessage(event) {
      console.log('WebView消息:', event);
    },
    onError(event) {
      console.error('WebView错误:', event);
      uni.showToast({
        title: '文件加载失败',
        icon: 'none'
      });
    }
  }
}
</script>

<style scoped>
.webview-page {
  width: 100%;
  height: 100vh;
}

.webview-content {
  width: 100%;
  height: 100%;
}
</style>
